/*
 * Messages.java
 *
 * Created on 16 de noviembre de 2006, 11:46
 *
 * To change this template, choose Tools | Template Manager
 * and open the template in the editor.
 */

package occho.view.resources ;

import java.awt.Color;
import java.text.DateFormat;
import java.text.NumberFormat;
import java.util.Locale;
import java.util.MissingResourceException;
import java.util.ResourceBundle;
import java.util.StringTokenizer;

/**
 * Contiene el objeto locale
 * @author Juan Antonio
 */
public class Messages {
    
        private static Locale locale = Locale.getDefault();
        
	// Nombre del fichero Properties = messages.properties

        /**
         * BUNDLE_NAME_ALUMNOS
         */
        public static final String BUNDLE_NAME_ALUMNOS = Messages.class.getPackage().getName()+".AlumnosFrame";
        /**
         * BUNDLE_NAME_ASIGNATURAS
         */
        public static final String BUNDLE_NAME_ASIGNATURAS = Messages.class.getPackage().getName()+".AsignaturasFrame";
        /**
         * BUNDLE_NAME_BORRAR_TESTS
         */
        public static final String BUNDLE_NAME_BORRAR_TESTS = Messages.class.getPackage().getName()+".BorrarTestsFrame";
        /**
         * BUNDLE_NAME_CREAR_TEST
         */
        public static final String BUNDLE_NAME_CREAR_TEST = Messages.class.getPackage().getName()+".CrearTestFrame";
        /**
         * BUNDLE_NAME_LOG
         */
        public static final String BUNDLE_NAME_LOG = Messages.class.getPackage().getName()+".LogFrame";
        /**
         * BUNDLE_NAME_LOGIN
         */
        public static final String BUNDLE_NAME_LOGIN = Messages.class.getPackage().getName()+".LoginFrame";
        /**
         * BUNDLE_NAME_OCCHO_VIEW
         */
        public static final String BUNDLE_NAME_OCCHO_VIEW = Messages.class.getPackage().getName()+".OcchoView";
        /**
         * BUNDLE_NAME_PREGUNTA
         */
        public static final String BUNDLE_NAME_PREGUNTA = Messages.class.getPackage().getName()+".PreguntaFrame";
        /**
         * BUNDLE_NAME_PROFESORES
         */
        public static final String BUNDLE_NAME_PROFESORES = Messages.class.getPackage().getName()+".ProfesoresFrame";
        /**
         * BUNDLE_NAME_REALIZAR_TEST
         */
        public static final String BUNDLE_NAME_REALIZAR_TEST = Messages.class.getPackage().getName()+".RealizarTestFrame";
        /**
         * BUNDLE_NAME_REGISTRO
         */
        public static final String BUNDLE_NAME_REGISTRO = Messages.class.getPackage().getName()+".RegistroFrame";
        /**
         * BUNDLE_NAME_RESULTADOS_ALUMNO
         */
        public static final String BUNDLE_NAME_RESULTADOS_ALUMNO = Messages.class.getPackage().getName()+".ResultadosAlumnoFrame";
        /**
         * BUNDLE_NAME_RESULTADOS_PROFESOR
         */
        public static final String BUNDLE_NAME_RESULTADOS_PROFESOR = Messages.class.getPackage().getName()+".ResultadosProfesorFrame";
        

        // Tendra tabla con las entradas en el idioma elegido
	private static ResourceBundle RESOURCE_BUNDLE = ResourceBundle.getBundle(BUNDLE_NAME_OCCHO_VIEW);

        // Cambia la localizacion
        /**
         * Cambia la localizacion
         * @param l
         */
        public static void setLocale(Locale l) {
		// Recarga las entradas de la tabla
		//RESOURCE_BUNDLE = ResourceBundle.getBundle(BUNDLE_NAME, locale);   
                locale = l;
	}

        // Devuelve una entrada de la tabla
        /**
         * Devuelve una entrada de la tabla
         * @param key
         * @param bundle
         * @return String
         */
        public static String getString(String key, String bundle) {
            RESOURCE_BUNDLE = ResourceBundle.getBundle(bundle, locale);
            try {			
                    return RESOURCE_BUNDLE.getString(key);
            } catch (MissingResourceException e) {
                    return '!' + key + '!';
            }
	}
        
        /**
         * Devuelve el color
         * @param key
         * @param bundle
         * @return El color seleccionado
         */
        public static Color getColor(String key, String bundle) {
            RESOURCE_BUNDLE = ResourceBundle.getBundle(bundle, locale);
            String color = RESOURCE_BUNDLE.getString(key);
            StringTokenizer tokenizer = new StringTokenizer(color, ", ");
            int[] rgb = new int[tokenizer.countTokens()];
            int i = 0;
            while(tokenizer.hasMoreTokens()) {
                rgb[i] = Integer.valueOf(tokenizer.nextToken()).intValue();
            }
            return new Color(rgb[0], rgb[1], rgb[2]);
        }
        
        /**
         * Devuelve dateFormat
         * @return El formato de la fecha
         */
        public static DateFormat getDateFormat() {
            return DateFormat.getDateInstance(DateFormat.DEFAULT, locale);
        }
        
        /**
         * Devuelve dateFormat
         * @return NumberFormat
         */
        public static NumberFormat getNumberFormat() {
            return NumberFormat.getNumberInstance(locale);
        }
}
